<?php 
//执行登录
$username = $_POST['username'];
$email = $_POST['email'];

if($username=='' || $email==''){
	qiMsg("用户名和Email都不能为空！");
}elseif(valid_email($email) == false){
	qiMsg("Email书写不正确！");
}else{
	$isemail = $DB->once_num_rows("select * from ".dbprefix."app_user where email='$email'");
	if($isemail > 0){
		
		//如果Email存在就跳转到验证密码页面
		header("Location: index.php?app=user&ac=plugin&plugin=qq&in=email&email=".$email);
		
	}else{
		$pwd = random(5,0);
		$DB->query("instert into ".dbprefix."app_user (`pwd`,`email`) values ('$pwd','$email') ");
		$userid = $DB->insert_id();
		
		//用户信息
		$arrData = array(
			'userid'			=> $userid,
			'username' 	=> $username,
			'email'		=> $email,
			'ip'			=> getIp(),
			'count_score'	=> '1000',
			'addtime'	=> time(),
			'uptime'	=> time(),
		);
		
		//插入用户信息
		$DB->insertArr($arrData,'app_user_info');
		
		$userData = $DB->once_fetch_assoc("select * from ".dbprefix."app_user_info where userid='$userid'");
		
		//发送系统消息(恭喜注册成功)
		$msg_userid = '0';
		$msg_touserid = $userid;
		$msg_content = '亲爱的 '.$username.' ：<br />您成功加入了 '
									.$TS_SITE['base']['site_title'].'<br />在遵守本站的规定的同时，享受您的愉快之旅吧!<br />你除了能用QQ登录外，还可以用Email登录本站<br />登录Email：'.$email.'<br />登录密码：'.$pwd;
		aac('message',$DB)->sendmsg($msg_userid,$msg_touserid,$msg_content);
		
		$_SESSION['tsuser']	= $userData;
	
		header("Location: index.php");
	}
	
}